import 'package:flutter/cupertino.dart';
import 'package:videotop/base_model.dart';

import '../myinfo.dart';
import '../util.dart';

/// created by hx
///    2021/1/26:9:23

class SigninModel extends BaseModel{
  int day;
  Util util;
  MyInfo myInfo;
  BuildContext context;
  SigninModel(this.context,this.day,this.util,this.myInfo);

  List<String> days = ['Day 0','Day 1','Day 2','Day 3','Day 4','Day 5','Day 6','Day 7'];
  List<int> coins = [0,1,2,2,3,3,3,5];
  List<String> icons = ['coins1','coins1','coins2','coins2','coins3','coins3','coins3','coins4'];
  int week;

  getInit() async{
    week = util.spfs.getInt('qdweek${myInfo.uid}')??1;
    var now = DateTime.fromMillisecondsSinceEpoch(util.urlTime);
    var count = now.difference(DateTime(now.year)).inDays;
    int cha = count - day;
    if(cha == 1 || cha == -365 || cha == -364){
      week++;
      if(week == 8)
        week = 1;
    }else{
      week = 1;
    }
    day = count;
    notifyListeners();
  }

  getQianDao(){
    util.spfs.setInt('qdday${myInfo.uid}', day);
    util.spfs.setInt('qdweek${myInfo.uid}', week);
    int coin = coins[week];
    util.setGold(myInfo.gold+coin, 2,myInfo.uid).then((value) {
      if (value == 1) {
        myInfo.gold += coin;
        util.showToast('Check in successed');
      } else {
        util.showToast('Check in failed');
      }
    });
    Navigator.pop(context);
  }
}